package com.weitu.workflow.flowManagement.service;

import com.alibaba.fastjson.JSONObject;
import com.weitu.permission.user.entity.User;
import com.weitu.workflow.flowManagement.entity.WorkItemInfo;
import com.weitu.workflow.flowManagement.entity.WorkflowInstance;
import com.weitu.workflow.flowManagement.entity.WorkflowReview;
import com.weitu.workflow.flowManagement.entity.WorkflowTaskInstance;
import org.fireflow.engine.IProcessInstance;
import org.fireflow.engine.definition.WorkflowDefinition;
import org.fireflow.engine.definition.WorkflowDefinitionInfo;
import org.fireflow.kernel.KernelException;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 工作流管理
 * 进行工作流流程的管理
 * Created by Administrator on 2017/3/17.
 */
public interface FlowManagementService {
    /***
     * 启动工作流实例并运行
     * @param businessIdentity 业务标识
     * @param businessId 业务id
     * @param businessContent 业务描述
     * @param actorId 创建人
     * @return IProcessInstance
     */
    IProcessInstance flowCreateAndRun(String businessIdentity,String businessId,String businessContent,String actorId) throws Exception;
    /***
     * 启动工作流实例并运行
     * @param businessIdentity 业务标识
     * @param businessId 业务id
     * @param actorId 创建人
     * @param dataMap  流程变量
     * @return IProcessInstance
     */
    IProcessInstance flowCreateAndRun(String businessIdentity,String businessId,String businessContent,String actorId,Map<String,String> dataMap) throws Exception;

    /***
     * 根据业务id查询业务流程实例
     * @param businessId
     * @return
     */
    public WorkflowInstance queryWorkflowInstanceByBusinessId(String businessId);
    /***
     * 根据业务id查询业务流程实例
     * @param workItemId
     * @return
     */
    public WorkflowInstance queryWorkflowInstanceByWorkItemId(String workItemId);
    /***
     * 根据流程实例id查询任务实例集合
     * @param workflowInstanceId
     * @return List<WorkflowTaskInstance>
     */
    public List<WorkflowTaskInstance> queryTaskInstanceListByWorkflowId(String workflowInstanceId);
    /***
     * 根据任务实例id查询工作项集合
     * @param workflowTaskInstanceId
     * @return List<WorkItemInfo>
     */
    public List<WorkItemInfo> queryWorkItemInfoListByTaskInstanceId(String workflowTaskInstanceId);

    /***
     * 根据业务标识查询流程定义信息
     * @param businessIdentity
     * @return
     */
    WorkflowDefinitionInfo queryWorkflowDefinitionInfoByBusinessIdentity(String businessIdentity);

    /***
     * 根据流程实例id保存业务内容
     * @param processInstanceId
     */
    void saveOrUpdateBusinessContent(String processInstanceId,String businessContent);

    /************************************工作项管理************************************************************************/
    /***
     * 根据用户名查询工作项数量
     * @param paramMap
     * @return
     */
    public int queryWorkItemCount(Map<String,Object> paramMap);
    /***
     * 根据用户名查询工作项列表
     * @param paramMap
     * @return
     */
    public List<WorkItemInfo> queryWorkItemList(Map<String,Object> paramMap);
    /***
     * 根据工作项id查询工作项信息
     * @param workItemId
     * @return
     */
    public WorkItemInfo queryWorkItemInfoByWorkItemId(String workItemId);
    /***
     * 根据工作项id查询业务表单地址
     * @param workItemId
     * @param formType  0:只读表单；1：编辑表单
     * @return
     */
    public String queryBusinessFormByWorkItemId(String workItemId,int formType);

    /***
     * 根据工作项id查询工作流处理意见
     * @param workItemId
     * @return
     */
    public WorkflowReview queryWorkflowReviewByWorkItemId(String workItemId);

    /***
     * 从request中获取审批意见参数
     * @param request
     * @param requestName
     * @return
     */
    WorkflowReview getWorkflowReviewByRequest(HttpServletRequest request,String requestName,String workItemId);

    /***
     * 保存处理结果
     * @param workflowReview
     * @return
     */
    boolean saveWorkflowReview(WorkflowReview workflowReview);

    /***
     * 结束工作项
     * @param workItemId
     */
    void workItemComplete(String workItemId) throws KernelException;
}
